package com.hnkywl.sts.dao.htgl;

import com.hnkywl.sts.entity.htgl.Ht;
import com.hnkywl.sts.entity.jhgl.Jkd;
import net.ruixin.orm.hibernate.Page;
import net.ruixin.orm.hibernate.SimpleHibernateTemplate;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: jerry
 * Date: 13-4-8
 * Time: 下午1:32
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class HtDao extends SimpleHibernateTemplate<Ht,Long> {
    public Page<Ht> findHtList(int pageNo, int pageSize) {
        String hql;
        List<Object> param = new ArrayList<Object>();
        StringBuilder condition = new StringBuilder();
        Page<Ht> page = new Page<Ht>(pageNo, pageSize, 0);
        //==============条件拼接===============

        //==============记录数量===============
        hql = "select count(*) from Ht ";
        if (condition.length() != 0)
            hql = hql + " where " + condition;
        Long c = null;
        if (param.size() != 0) {
            c = (Long) findUnique(hql, param.toArray());
            page.setTotalCount(c.intValue());
        } else {
            c = (Long) findUnique(hql);
            page.setTotalCount(c.intValue());
        }
        if (c == 0)
            return page;
        //==============查询结果===============
        hql = "from Ht";
        if (condition.length() != 0)
            hql = hql + " where " + condition + "order by dateCreated desc";
        if (param.size() != 0)
            return find(page, hql, param.toArray());
        return find(page, hql);
    }
}
